﻿using System;
using System.Windows.Data;

namespace TheMovieDb.Example.Converters
{
    [ValueConversion(typeof(object), typeof(string))]
    public class CastMemberConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
        {
            var person = value as TmdbCastPerson;
            if (person == null)
                return "";
            string p = string.Format("{0}: {1}", person.Job, person.Name);
            if (!string.IsNullOrEmpty(person.Character))
                p += " as " + person.Character;
            return p;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
        {
            // we don't intend this to ever be called
            return null;
        }
    }
}
